package com.ning.json;

import com.google.gson.Gson;

import java.util.ArrayList;

/**
 * Created by ning on 2017/6/8.
 */
public class GsonDemo {
    static class Number {
        public int x;
        public int y;

        public Number(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return gson.toJson(this);
        }
    }

    public static Gson gson = new Gson();

    public static void main(String[] args) {
        ArrayList<Number> numbers = new ArrayList<>();

        numbers.add(new Number(1, 3));
        numbers.add(new Number(2, 5));

        String json = gson.toJson(numbers);
        System.out.println(json);

        ArrayList<Number> numberArrayList = null;

//        numberArrayList = gson.fromJson(json, ArrayList.class);
//
//        for (Number n : numberArrayList) {
//            System.out.println(n.toString());
//        }

        System.out.println(gson.fromJson(json, ArrayList.class));

    }
}
